{layout name="public/layout" /}

<div id="content-wrapper">

  <div class="container-fluid">
    <!-- DataTables Example -->
    <div class="card mb-3">
      <div class="card-header">
        <i class="fas fa-table"></i>
        管理员管理
      </div>
      <div class="card-body">
        <div class="table-responsive">
          <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
            <thead>
            <tr>
              <th></th>
              <th>ID</th>
              <th>管理员</th>
              <th>管理员手机号</th>
              <th>头像</th>
              <th>是否是超级管理员</th>
              <th>更新时间</th>
              <th>创建时间</th>
              <th>操作</th>
            </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>

  </div>
  <!-- /.container-fluid -->
</div>
<!-- /.content-wrapper -->
<script type="text/javascript">

    $(document).ready(function() {
        //配置DataTables默认参数
        $('#dataTable').dataTable({
            // paging: false,
            // scrollY: 400
            ajax: {
                url: "/api/adminUser/list",
                type: "POST",
                data: function(data){
                    data.page = Math.ceil((data.start+1) / data.length);
                    data.per_page = data.length;
                    return data;
                },
                dataFilter: function (data) {
                    var json = jQuery.parseJSON( data );
                    json = json.data;
                    json.recordsTotal = json.total;
                    json.recordsFiltered = json.total;
                    return JSON.stringify( json );
                },

            },
            "columns": [
                {

                },
                {
                    data: "id",

                },
                {
                    data: "admin_name"
                },
                {
                    data: "admin_mobile"
                },
                {
                    data: "admin_avatar"
                },
                {
                    data: "is_super_text"
                },
                {
                    data: "update_time"
                },
                {
                    data: "create_time"
                },
                {

                }
            ],
            // lengthChange: false,
            // pageLength: 10,

        });
        $('.table-sort tbody').on( 'click', 'tr', function () {
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            else {
                $('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        });
    });

    function ajaxEdit(that,type,id){
        var obj = $(that);
        var value = obj.val();
        var data = {type:type,id:id,value:value};
        var url = "/api/adminUser/edit";

        postDataNoErrorAlert("post",url,data,false,false,false,function(obj){
            showTips(obj.msg);
            if( obj.code == 200 ){
                location.replace(location.href);
            }
        });
    }

    function delData(id){
        var data = {id:id};
        var url = "/api/adminUser/delete";
        delDialog(data,url);
    }

    function delAll(){
        var id = "";
        $('input[name="id_arr[]"]:checked').each(function(){
            var value = $(this).val();
            id += "|" + value;
        });
        var msg = "";
        if( isEmptyOrNull(id) ){
            msg = "请选择删除项";
            showTips( msg );
            return false;
        }
        delData(id);
    }


</script>
